<template>
	<view class="container">
		<view class="tui-order-header">
			<!-- <image src="/static/images/mall/img_bg_3x.png" mode="widthFix" class="tui-img-bg"></image> -->
			<view class="tui-header-content">
				<view>
					<view class="tui-status-text">
						<!-- <label v-if="orderInfo.orderType == 6">景区订单</label> -->
						<div class="font-20 weight-700">{{orderInfo.orderStatusText||''}}</div>
						<view class="flex mg-l-20">
							<view class="tui-size-24" style="padding-top: 5rpx;">￥</view>
							<view class="tui-price-large">{{orderInfo.actualPrice}}</view>
							<view class="font-12 mg-l-10" @tap="popupDetail=true">详情 ></view>
						</view>
					</view>
					<view class="tui-reason">
						<text class="tui-reason-text" v-if="orderInfo.totalSecond>0&&orderInfo.orderStatus===0">等待买家付款
						</text>
						<tui-countdown v-if="orderInfo.totalSecond>0" :time="orderInfo.totalSecond||0" :hours="false"
							:isColon="false" backgroundColor="#333" borderColor="#333" color="#fff" />
					</view>
				</view>
				<!-- <image :src="getImg(orderInfo.orderStatus)" class="tui-status-img" mode="widthFix"></image> -->
			</view>
		</view>
		<view class="tui-order-item" v-if="orderInfo.shopsName">
			<tui-list-cell :hover="false" :arrow="true" @click="goodsDetail()">
				<view class="tui-goods-title">
					{{orderInfo.shopsName||''}}
				</view>
			</tui-list-cell>

			<tui-list-cell :hover="false" :arrow="false">
				<view class="tui-addr-text">
					<span class="weight-500">使用日期：</span><span
						class="default-color">{{orderInfo.appointDate|formatDay}}</span> 当日有效
				</view>
				<view class="tui-addr-text">
					<span class="weight-500">入园时间：</span><span>{{orderInfo.visitTime||''}}</span>
				</view>
			</tui-list-cell>

			<tui-list-cell :hover="false" :arrow="false">
				<div v-if="orderInfo.orderStatus==201 || orderInfo.orderStatus==300"
					class="qrCode tui-order-part mg-t-10">
					<div class="font-16 width-600">凭[入院码]直接入园</div>
					<div class="flex justify-center align-center" style="width: 670rpx;height: a;">
						<div class="flex-left-header">入园码</div>
						<div class="flex justify-center align-start flex-col mg-l-20 mg-t-20" style="width: 550rpx;">
							<div class="text-value" >
								入园码：{{orderQrcode}} <!-- {{(orderInfo.uucode !='' && orderInfo.uucode!=null)?orderInfo.uucode:orderInfo.shippingNo}} -->
							</div>
							<canvas v-show="orderInfo.orderStatus==201 || orderInfo.orderStatus==300"
								canvas-id="memberCode" style="width: 410rpx; height: 410rpx;"></canvas>
								
						</div>
						<div class="flex-right-header" style="width: 100rpx;">复制</div>
					</div>
				</div>
			</tui-list-cell>

			<tui-list-cell :hover="false">
				<view class="font-16 weight-700">
					入园地址
				</view>
				<view class="tui-desc-txt">
					{{shopsVo.details||''}}
				</view>
			</tui-list-cell>

			<tui-list-cell :hover="false">
				<view class="font-14 weight-700">
					退改规则
				</view>
				<view class="tui-desc">
					<div class="tui-desc-tag">未用随时退</div>
					<view class="flex mg-t-10">
						<view class="tui-item-content">未消费随时可退款，最晚1个工作日内完成退款审核。</view>
					</view>
				</view>
				<view class="tui-desc">
					<div class="tui-desc-tag">过期自动退</div>
					<view class="flex mg-t-10">
						<view class="tui-item-content">过期后未消费自动申请退款。</view>
						<view class="tui-item-content">下单后不支持改期。</view>
					</view>
				</view>
				<view class="flex justify-sb mg-t-10" @tap="callMobile">
					<div class="flex flex-col justify-center align-start">
						<div class="font-16">
							供应商电话</div>
						<div class="font-14 mg-t-5 tui-gray">
							推出票/协商退改
						</div>
					</div>
					<view class="tui-order-flex mg-r-20">
						<tui-icon name="voipphone" size="24"></tui-icon>
					</view>
				</view>
				<view class="flex justify-sb mg-t-10">
					<div class="flex flex-col justify-center align-center">
						<div class="font-16">
							客服</div>
						<div class="font-14 mg-t-5 tui-gray">
							问题咨询/在线帮助
						</div>
					</div>
					<view class="tui-order-flex mg-r-20">
						<tui-icon name="kefu" size="24"></tui-icon>
					</view>
				</view>
			</tui-list-cell>
		</view>

		<view class="tui-order-info">

		</view>

		<!-- 		<view class="tui-order-info mg-l-10">
			<view class="tui-order-flex align-center justify-sb" @click="switchShops(orderInfo.shopsSn)">
				<view class="font-20 weight-500">{{shopsVo.name||''}}</view>
				<view class="tui-item-content mg-l-50 mg-r-20">景点详情 ></view>
			</view>
		</view> -->


		<view class="tui-order-info" v-if="orderInfo.orderSn">
			<tui-list-cell :hover="false">
				<view class="tui-order-title">
					订单信息
				</view>
			</tui-list-cell>
			<view class="tui-order-content">
				<view class="tui-order-flex">
					<view class="tui-item-title">订单号:</view>
					<view class="tui-item-content">{{orderInfo.orderSn||''}}</view>
					<view class="tui-black-txt mg-l-5" @tap="copyText(orderInfo.orderSn)">复制</view>
				</view>
				<view class="tui-order-flex" v-if="orderInfo.payTime">
					<view class="tui-item-title">支付时间:</view>
					<view class="tui-item-content">{{orderInfo.payTime}}</view>
				</view>
				<view class="tui-order-flex" v-if="orderInfo.payType">
					<view class="tui-item-title">支付方式:</view>
					<!-- <view class="tui-item-content">{{getPayTypeText(orderInfo.payType)}}</view> -->
					<view class="tui-item-content">在线支付</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">合计</view>
					<view class="tui-item-content flex">
						<view>￥</view>
						<view>{{orderInfo.orderPrice}}</view>
					</view>
				</view>
				<view class="tui-order-flex ">
					<view class="tui-item-title">优惠券</view>
					<view class="tui-item-content default-color">{{orderInfo.couponTitle||''}} -
						￥{{orderInfo.couponPrice||0}}</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">实付款</view>
					<view class="tui-item-content flex">
						<view class="default-color">￥</view>
						<view class="default-color">{{orderInfo.actualPrice||0}}</view>
					</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">联系人:</view>
					<view class="tui-item-content">{{orderInfo.consignee}}</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">联系电话:</view>
					<view class="tui-item-content">{{orderInfo.mobile}}</view>
				</view>
				<!-- <view class="tui-order-flex">
					<view class="tui-item-title">创建时间:</view>
					<view class="tui-item-content">{{orderInfo.addTime||''}}</view>
				</view> -->
				<view class="tui-order-flex" v-if="orderInfo.confirmTime">
					<view class="tui-item-title">核销时间:</view>
					<view class="tui-item-content">{{orderInfo.confirmTime||''}}</view>
				</view>
				<view class="tui-order-flex" v-if="orderInfo.postscript">
					<view class="tui-item-title">订单备注:</view>
					<view class="tui-item-content">{{orderInfo.postscript || ''}}</view>
				</view>
			</view>
		</view>
		<view class="tui-tabbar tui-order-btn">
			<!--			<view class="tui-btn-ml">-->
			<!--				<tui-button type="warning" plain width="152rpx" height="56rpx" :size="26" shape="circle"-->
			<!--					@click="againBuy">再次购买</tui-button>-->
			<!--			</view>-->
			<view class="tui-btn-ml" v-if="orderInfo.totalSecond>0&&orderInfo.orderStatus==0">
				<tui-button plain width="152rpx" height="56rpx" :size="26" shape="circle" type="danger"
					@click="payOrder">立即支付</tui-button>
			</view>
			<view class="tui-btn-mr"
				v-if="orderInfo.totalSecond>0||(orderInfo.orderStatus==0||orderInfo.orderStatus==201)">
				<tui-button plain width="152rpx" height="56rpx" :size="26" shape="circle" @click="cancelOrder">取消订单
				</tui-button>
			</view>
			<view class="tui-btn-mr" v-if="orderInfo.handleOption.comment===true && orderInfo.commentCount == 0">
				<tui-button type="green" plain width="152rpx" height="56rpx" :size="26" shape="circle"
					@click="postComment">评价晒单</tui-button>
			</view>
			<view class="tui-btn-mr" v-if="orderInfo.commentCount > 0">
				<tui-button type="green" plain width="152rpx" height="56rpx" :size="26" shape="circle"
					@click="lookComment">查看评价</tui-button>
			</view>
			<!-- <view class="tui-btn-ml" v-if="orderInfo.handleOption.comment===true||orderInfo.commentCount > 0">
				<tui-button @click="applyRefund" type="gray" plain width="152rpx" height="56rpx" :size="26"
					shape="circle">申请退款</tui-button>
			</view> -->
		</view>
		<tui-bottom-popup :zIndex="1002" :maskZIndex="1001" :show="popupDetail" @close="popupDetail=false">
			<view class="tui-pop-header">
				票详情
			</view>
			<block v-for="(item, index) in orderGoods" :key="index">
				<tui-list-cell padding="0" @click="goodsDetail()">
					<view class="tui-goods-item">
						<!-- <image :src="item.listPicUrl" class="tui-goods-img"></image> -->
						<view class="tui-goods-center">
							<view class="tui-goods-name">{{item.goodsName||''}}</view>
							<view class="tui-goods-attr">{{item.goodsSpecifitionNameValue||''}}</view>
						</view>
						<view class="tui-price-right default-color">
							<view>￥{{item.retailPrice}}</view>
							<view>x{{item.number}}</view>
						</view>
					</view>
				</tui-list-cell>
			</block>
		</tui-bottom-popup>
	</view>
</template>

<script>
	const util = require("@/utils/util.js");
	import uQRCode from '@/libs/uqrcode'

	export default {
		data() {
			return {
				qrcode: false,
				orderId: 0,
				orderInfo: {
					province: '',
					city: '',
					district: '',
					address: '',
					handleOption: {}
				},
				orderGoods: [],
				handleOption: {},
				sweixin: null,
				popupDetail: false,
				shopsVo: {},
				orderQrcode:''
			}
		},
		filters: {
			formatDay(val) {
				var showVal = val;
				if (val && val.length > 10) {
					showVal = val.substr(0, 10)
				}
				var weekVal = util.weekDay(showVal);
				return showVal + ' ' + weekVal + ' ';
			}
		},
		onLoad: function(options) {
			let that = this;
			// 页面初始化 options为页面跳转所带来的参数
			that.orderId = options.id;

			// #ifdef APP-PLUS
			plus.share.getServices(function(s) {
				var shares = {};
				for (var i = 0; i < s.length; i++) {
					var t = s[i];
					shares[t.id] = t;
				}

				that.sweixin = shares['weixin']
			}, function(e) {
				console.log("获取分享服务列表失败：" + e.message);
			});
			//#endif

			this.getOrderDetail();
		},
		methods: {
			callMobile: function() {
				uni.makePhoneCall({
					phoneNumber: this.shopsVo.telephone
				})
			},
			copyText(val) {
				uni.setClipboardData({
					data: val,
					complete() {
						uni.showToast({
							title: "已复制到剪贴板"
						})
					}
				})
			},
			getPayTypeText(payType) {
				if (payType == 1) {
					return '微信支付';
				}
				if (payType == 2) {
					return '余额支付';
				}
				if (payType == 3) {
					return '支付宝支付';
				}
			},
			switchShops(shopsSn) {
				uni.navigateTo({
					url: `/pagesA/scenic/shops?shopsSn=${shopsSn}`
				})
			},
			goMiniProgram() {
				let that = this;
				// #ifdef MP-WEIXIN
				uni.navigateToMiniProgram({
					appId: 'wx6885acbedba59c14',
					path: 'pages/result/result?nu=' + that.orderInfo.shippingNo + '&uerysource=third_xcx',
					envVersion: 'release',
					success(res) {}
				})
				// #endif

				//#ifdef APP-PLUS
				that.sweixin ? that.sweixin.launchMiniProgram({
					id: 'gh_a63a83fbf60a',
					path: 'pages/result/result?nu=' + that.orderInfo.shippingNo + '&uerysource=third_xcx',
					type: 0
				}) : plus.nativeUI.alert("当前环境不支持打开'快递100'小程序!");
				//#endif
			},
			changeQrcode() {
				this.qrcode = !this.qrcode
			},
			getOrderDetail() {
				let that = this;
				util.request('activities/orderdetail', {
					orderId: that.orderId
				}).then(function(res) {
					if (res.code === 0) {
						that.orderInfo = res.orderInfo;
						that.orderGoods = res.orderGoods;
						that.handleOption = res.orderInfo.handleOption;
						if ((that.orderInfo.payStatus == 1 || that.orderInfo.payStatus == 2) && that.orderInfo
							.orderStatus === 0) {
							that.orderInfo.totalSecond = util.expireTime(that.orderInfo.expireTime)
						}
						that.getShopsDetail(that.orderInfo.shopsId)
						
						that.orderQrcode = that.orderInfo.shippingNo;
						uQRCode.make({
							canvasId: 'memberCode',
							componentInstance: this,
							text: res.orderInfo.id,
							size: uni.upx2px(390),
							margin: 20,
							backgroundColor: '#ffffff',
							foregroundColor: '#000000',
							fileType: 'jpg',
							correctLevel: uQRCode.defaults.correctLevel,
							success: res => {
								console.log(res)
							}
						});
					}
				});
			},
			
			async getImageInfo({ imgSrc }) {
				return new Promise((resolve, errs) => {
					uni.getImageInfo({
						src: imgSrc,
						success: function(image) {
							resolve(image);
						},
						fail(err) {
							errs(err);
						}
					});
				});
			},
			getShopsDetail(shopsId) {
				let that = this;
				util.request('shops/detailById', {
					shopsId: shopsId
				}).then(function(res) {
					if (res.code === 0) {
						that.shopsVo = res.data;
					}
				});
			},
			getImg: function(orderStatus) {
				let base = '/static/images/mall/'
				if (orderStatus == -1 || orderStatus == 0) {
					return base + 'img_order_payment3x.png'
				}
				if (orderStatus == 100 || orderStatus == 101 || orderStatus == 102) {
					return base + 'img_order_closed3x.png'
				}
				if (orderStatus == 201) {
					return base + 'img_order_send3x.png'
				}
				if (orderStatus == 300) {
					return base + 'img_order_received3x.png'
				}
				if (orderStatus == 301) {
					return base + 'img_order_signed3x.png'
				}
			},
			againBuy() {
				let that = this;
				util.request('cart/addByOrder', {
					orderId: that.orderId
				}).then(function(res) {
					if (res.code === 0) {
						uni.switchTab({
							url: '/pages/cart/cart',
						});
					} else {
						util.toast(res.msg)
					}
				});
			},
			applyRefund() {
				let that = this;
				uni.navigateTo({
					url: '/pages/ucenter/refund/refund?orderId=' + that.orderId
				})
			},
			postComment() {
				let that = this;
				uni.navigateTo({
					url: '/pages/commentPost/commentPost?type=0' + '&orderId=' + that.orderId,
				})
			},
			lookComment() {
				let that = this;
				uni.navigateTo({
					url: '/pages/comment/comment?type=0' + '&orderId=' + that.orderId,
				})
			},
			cancelOrder() {
				let that = this;
				let orderInfo = that.orderInfo;

				var orderStatus = orderInfo.orderStatus;
				var errorMessage = '';
				switch (orderStatus) {
					case 300: {
						errorMessage = '订单已发货';
						break;
					}
					case 301: {
						errorMessage = '订单已收货';
						break;
					}
					case 100: {
						errorMessage = '订单已过期';
						break;
					}
					case 101: {
						errorMessage = '订单已取消';
						break;
					}
					case 102: {
						errorMessage = '订单已删除';
						break;
					}
					case 401: {
						errorMessage = '订单已退款';
						break;
					}
					case 402: {
						errorMessage = '订单已退货';
						break;
					}
				}

				if (errorMessage != '') {
					util.toast(errorMessage);
					return false;
				}

				uni.showModal({
					title: '',
					content: '确定要取消此订单？',
					success: function(res) {
						if (res.confirm) {

							util.request('order/cancelOrder', {
								orderId: orderInfo.id
							}, 'POST').then(function(res) {
								if (res.code === 0) {
									uni.showModal({
										title: '提示',
										content: res.msg,
										showCancel: false,
										confirmText: '继续',
										success: function(res) {
											uni.reLaunch({
												url: '/pages/ucenter/order/order',
											});
										}
									});
								}
							});

						}
					}
				});
			},
			payOrder() {
				let that = this;
				uni.navigateTo({
					url: '/pages/pay/pay?orderId=' + that.orderInfo.id + '&actualPrice=' + that.orderInfo
						.actualPrice,
				})
			},
			goodsDetail() {
				uni.navigateTo({
					url: '/pagesA/scenic/shops?shopsSn=' + this.orderInfo.shopsSn +
						'&shopsId=' + this.orderInfo.shopsId
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		background-color: #EEEEEE;
	}

	.tui-order-header {
		width: 100%;
		height: 120rpx;
		position: relative;
	}

	.tui-header-content {
		width: 100%;
		height: 160rpx;
		position: absolute;
		z-index: 10;
		left: 0;
		top: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 70rpx;
		box-sizing: border-box;
	}

	.tui-status-text {
		font-size: 36rpx;
		line-height: 36rpx;
		color: #6d5c5c;
		display: flex;
	}

	.tui-reason {
		font-size: 24rpx;
		line-height: 24rpx;
		color: rgba(254, 254, 254, 0.75);
		padding-top: 15rpx;
		display: flex;
		align-items: center;
	}

	.tui-reason-text {
		padding-right: 12rpx;
	}

	.tui-status-img {
		width: 80rpx;
		height: 80rpx;
		display: block;
	}

	.tui-flex-box {
		width: 100%;
		display: flex;
		align-items: center;
	}

	.tui-icon-img {
		width: 44rpx;
		height: 44rpx;
		flex-shrink: 0;
	}

	.tui-logistics {
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 24rpx 0 20rpx;
		box-sizing: border-box;
	}

	.tui-logistics-text {
		font-size: 28rpx;
		line-height: 32rpx;
	}

	.tui-logistics-time {
		font-size: 24rpx;
		line-height: 24rpx;
		padding-top: 16rpx;
		color: #666;
	}

	.tui-addr {
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding-left: 20rpx;
		box-sizing: border-box;
	}

	.tui-addr-userinfo {
		font-size: 30rpx;
		line-height: 30rpx;
		font-weight: bold;
	}

	.tui-addr-text {
		font-size: 24rpx;
		line-height: 30rpx;
		padding-top: 16rpx;
	}

	.tui-addr-tel {
		padding-left: 40rpx;
	}

	.tui-order-item {
		border-radius: 20rpx;
		overflow: hidden;
		margin: 20rpx;
	}

	.tui-goods-title {
		width: 100%;
		font-size: 26rpx;
		line-height: 26rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tui-goods-item {
		width: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
	}

	.tui-goods-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 10rpx;
		display: block;
		flex-shrink: 0;
	}

	.tui-goods-center {
		flex: 1;
		padding: 20rpx 8rpx;
		box-sizing: border-box;
	}

	.tui-goods-name {
		max-width: 310rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 26rpx;
		line-height: 32rpx;
	}

	.tui-goods-attr {
		font-size: 22rpx;
		color: #888888;
		line-height: 32rpx;
		padding-top: 20rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.tui-price-right {
		text-align: right;
		font-size: 24rpx;
		color: #888888;
		line-height: 30rpx;
		padding-top: 20rpx;
	}

	.tui-goods-price {
		width: 100%;
		display: flex;
		align-items: flex-end;
		justify-content: flex-end;
		font-size: 24rpx;
	}

	.tui-size-24 {
		font-size: 24rpx;
		line-height: 24rpx;
	}

	.tui-price-large {
		font-size: 32rpx;
		line-height: 30rpx;
	}

	.tui-goods-info {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		background: #fff;
	}

	.tui-price-flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tui-size24 {
		padding-bottom: 24rpx;
		font-size: 24rpx;
		line-height: 24rpx;
		color: #888;
	}

	.tui-size32 {
		font-size: 32rpx;
		line-height: 32rpx;
		font-weight: 600;
	}

	.tui-pbtm20 {
		padding-bottom: 20rpx;
	}

	.tui-flex-shrink {
		flex-shrink: 0;
	}

	.tui-primary-color {
		color: #EB0909;
	}

	.tui-order-info {
		margin-top: 20rpx;
	}

	.tui-order-title {
		position: relative;
		font-size: 28rpx;
		line-height: 28rpx;
		padding-left: 12rpx;
		box-sizing: border-box;
	}

	.tui-order-title::before {
		content: '';
		position: absolute;
		left: 0;
		top: 0;
		border-left: 4rpx solid $color-default;
		height: 100%;
	}

	.tui-order-content {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		background: #fff;
		font-size: 24rpx;
		line-height: 30rpx;
	}

	.tui-order-flex {
		display: flex;
		padding-top: 24rpx;
	}

	.tui-order-flex:first-child {
		padding-top: 0
	}

	.tui-item-title {
		width: 132rpx;
		flex-shrink: 0;
	}

	.tui-item-content {
		color: #666;
	}

	.tui-safe-area {
		height: 450rpx;
		text-align: -webkit-center;
	}

	.tui-tabbar {
		width: 100%;
		height: 80rpx;
		background: #fff;
		position: relative;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 26rpx;
		padding-bottom: env(safe-area-inset-bottom);
		padding-top: 20rpx;
		z-index: 999;
	}

	.tui-btn-mr {
		margin: 10px;
	}

	.flex-left-header {
		writing-mode: vertical-rl;
		height: 400rpx;
		background-color: #000000;
		color: #FFFFFF;
		width: 50rpx;
		padding-top: 20rpx;
		border-radius: 10rpx 0 0 10rpx;
	}

	.flex-right-header {
		height: 400rpx;
		color: skyblue;
	}

	.tui-black-txt {
		color: skyblue;
	}

	.tui-desc {
		width: 100%;
		padding: 20rpx 0rpx;
		box-sizing: border-box;
		background: #fff;
		font-size: 24rpx;
		line-height: 30rpx;
	}

	.tui-desc-tag {
		border: 4rpx solid skyblue;
		padding: 5rpx;
		width: 120rpx;
		color: skyblue;
	}

	.tui-desc-txt {
		padding: 20rpx 0rpx;
		box-sizing: border-box;
		background: #fff;
		font-size: 24rpx;
		line-height: 30rpx;
	}

	.tui-gray {
		color: #666;
	}

	.tui-pop-header {
		width: 100%;
		font-size: 26rpx;
		line-height: 26rpx;
		margin-left: 40rpx;
		margin-top: 40rpx;
	}
</style>
